package recharge_management

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ThirdpartyBankListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 代收三方银行--列表
func NewThirdpartyBankListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ThirdpartyBankListLogic {
	return &ThirdpartyBankListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ThirdpartyBankListLogic) ThirdpartyBankList(req *types.ThirdpartyBankListRequest) (resp *types.ThirdpartyBankListResponse, err error) {
	rpcReq := rpc.ThirdpartyBankListRequest{
		AgentName: req.AgentName,
		BankName:  req.BankName,
		BankCode:  req.BankCode,
	}

	rpcResp, err := l.svcCtx.AssetsRpc.TenantChannel.ThirdpartyBankList(l.ctx, &rpcReq)
	if err != nil {
		return &types.ThirdpartyBankListResponse{
			Records: nil,
			CommonResp: types.CommonResp{
				Code:    rpcResp.CommonResp.Code,
				Message: rpcResp.CommonResp.Message,
			},
		}, err
	}

	var records []types.ThirdpartyBank
	for _, record := range rpcResp.Records {
		records = append(records, types.ThirdpartyBank{
			Id:        record.Id,
			AgentName: record.AgentName,
			BankName:  record.BankName,
			BankCode:  record.BankCode,
			Sort:      record.Sort,
			Status:    record.Status,
		})
	}

	return &types.ThirdpartyBankListResponse{
		Records: records,
		CommonResp: types.CommonResp{
			Code:    rpcResp.CommonResp.Code,
			Message: rpcResp.CommonResp.Message,
		},
	}, nil
}
